-
Notifications
You must be signed in to change notification settings - Fork 56
Use GOT for CHERI-RISC-V and align modifiers and relocations with RISC-V #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d624134 ("[lld][X86] Restore gotEntrySize.") (re-)introduced gotEntrySize and used it for various GOT calculations, but was not exhaustive (nor consistent; Symbol::getGotOffset was modified but not GotSection::finalizeContents, so we undercompute the size, on top of computing the wrong offsets for TLS), and since then even more uses have been added that use wordsize instead of gotEntrySize (presumably due to looking at the existing incorrect ones). This doesn't really matter upstream, as the only architecture where the two differ is X32, and from looking at the code it's not properly supported (e.g. TLS relaxation assumes LP64 sequences), but downstream in CHERI LLVM it does matter, as CHERI's pointers are more than just an integer address (a machine word). Note this ignores the special MipsGotSection; on MIPS, wordsize and gotEntrySize are the same, CHERI-MIPS is no longer something we support downstream and even when we did we didn't reuse that implementation.
cd663e2 to
9cafdd4
Compare
|
I'll deal with the clang-format bits I missed later (and won't be accepting the lld ones, that's upstream's formatting...) |
|
This can do a clean build of CheriBSD that passes all cheribsdtest tests. |
|
NB: The first commit is up for review upstream at llvm/llvm-project#142064 |
|
Now with opt-in .got.plt support (requires CTSRD-CHERI/cheribsd#2417 if enabled). |
RELRO sections are SHF_WRITE, so there's nothing wrong with the code here. This is how it's meant to work, and how things like GotSection are constructed.
CHERI-RISC-V no longer uses it, and Morello never has downstream.
This exists to support __cap_relocs for preemptible symbols, but that was always a bit broken and was replaced long ago even on CHERI-MIPS with proper ELF relocations (though the option not to still exists). CHERI-RISC-V never used this, and CheriBSD does not support it.
This was never on CHERI-RISC-V even when we used .captable, as we passed R_CHERI_CAPABILITY_TABLE_INDEX to ensure the relocation was in .rela.dyn and thus would also use cheriCapRel rather than cheriCapCallRel. Now the normal .got is used instead there isn't even a path that could use this.
LLD is now using a normal GOT so all the captable-related names are a misnomer, instead they should be the same as the normal GOT ones. We can also drop various other gratuitously-different relocations and modifiers whilst here. The idea was to make it possible to support mixing integer and capability mode instructions when it comes to instructions that need relocations, but that comes down to the same problem that R_RISCV_RELAX faces when it comes to .option arch, so we shouldn't be doing something special here that leads to a bunch of unnecessary divergence. As far as I know we don't have any assembly in our software stack that uses these modifiers, it all uses the pseudos that hide this detail.
We can just reuse R_RISCV_JUMP_SLOT when needed.
This has never actually been used (it only appeared to be used in LLD, but never was in practice), nor is it supported by any run-time linker.
…ions This will be needed to initialise .got.plt entries to refer to .plt[0]. The infrastructure is already mostly there, we just need to expose it via the addCapabilityRelocation interface and remove some assumptions.
This code is currently dead since we emit an all-zeroes PLT header on CHERI-RISC-V, but will soon be used. Fixes: 05652b9 ("[CHERI-RISC-V] Remove CSub")
This is currently behind an opt-in -z cheri-riscv-jump-slot flag as it requires support in CheriBSD, but in future will become the default and only supported mode.
arichardson
approved these changes
Jun 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.